package com.zzyy.study.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @auther zzyy
 * @create 2024-07-05 17:16
 */
@Configuration
public class MybatisPlusConfig
{
    /**
     * 启用多租户插件拦截
     * 如果用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 启用多租户插件拦截
        //interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new CustomTenantHandler()));
        //配置version乐观锁，mybatis结合mysql兜底，不能当作主力，只是简单处理吧并发修改
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //配置分页
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));

        return interceptor;
    }
}
